package controllers

import (
	"errors"
	"news/common/response"
	"news/constStatus"
	"news/logic"
	"news/models"

	"go.uber.org/zap"

	"github.com/gin-gonic/gin"
)

func CreateGroupHandler(c *gin.Context) {
	p := new(models.Group)
	if err := c.ShouldBindJSON(p); err != nil {
		response.ResponseErr(c, response.CodeInvalidParam)
		return
	}
	err := logic.CreateGroup(p)
	zap.L().Error("logic.CreateGroup", zap.Error(err))
	if err != nil {
		if errors.Is(err, constStatus.ErrorUserExist) {
			response.ResponseErr(c, response.CodeUserExist)
			return
		}
		response.ResponseErr(c, response.CodeServerBusy)
		return
	}
	response.ResponseSuccess(c, nil)

}
